package com.vint.mi;

/**
 *  1. done
 *  2. medium
 *  3. 数学
 *  移除K个值使剩下最小
 *  Info:
 *  12300002， 3， 首先判断前三位后面有无0,有的话先处理这种情况
 *  然后比较，删除的连续字符和替换它的字符比较，差距最大的胜出
 */
public class Mi9 {
    public static String solution(String line){
        String[] src = line.split(",");
        char[] chs = src[0].toCharArray();
        int l = Integer.parseInt(src[1]);
        int length = src[0].length();
        int i = l;
        for(i=l;i<chs.length;i++){
           if(chs[i]!='0'){
               break;
           }
        }
        if(i>l)return src[0].substring(i);

        StringBuffer sb = new StringBuffer(src[0]);
        for(i=0;i<l;i++)sb.append('0');
        String ret = sb.toString();
        int start = 0;
        long max = 0;
        for(i=0;i<length;i++){
            String sub1 = ret.substring(i,i+l);
            String sub2 = ret.substring(i+l,i+2*l);
            long ac =Long.parseLong(sub1)-Long.parseLong(sub2);
            if(ac > max ){
                max = ac;
                start = i;
            }
        }
        String ss = src[0].substring(start,start+l);
        return src[0].replace(ss,"");

    }

    public static void main(String[] args) {
        String ex1 = "10200,1";
        String ex2 = "1432219,3";
        //System.out.println(solution(ex1));
        System.out.println(solution(ex2));
    }
}
